package com.youyi.yyviewsdklibrary.View;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.support.v7.widget.SwitchCompat;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.lkx.liandianqinew.R;

public class MyNameDetailView extends LinearLayout {
    private Context mContext;
    private TextView mDetail;
    private ImageView mEnter;
    private ImageView mImg;
    private View mInflate;
    private TextView mName;
    private onItemClickListener mOnItemClickListener;
    private boolean mShowEnter;
    private boolean mShowSwitch;
    private SwitchCompat mSwitchCompat;

    public interface onItemClickListener {
        void onChecked(boolean z);

        void onItemClick(View view);
    }

    public MyNameDetailView(Context context) {
        super(context);
    }

    public void setOnItemClickListener(onItemClickListener onitemclicklistener) {
        this.mOnItemClickListener = onitemclicklistener;
    }

    public MyNameDetailView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, R.styleable.MyNameDetailView);
        int resourceId = obtainStyledAttributes.getResourceId(R.styleable.MyNameDetailView_imgSrc, R.drawable.view_close);
        String string = obtainStyledAttributes.getString(R.styleable.MyNameDetailView_viewName);
        String string2 = obtainStyledAttributes.getString(R.styleable.MyNameDetailView_viewDetail);
        int color = obtainStyledAttributes.getColor(R.styleable.MyNameDetailView_tintColor, context.getResources().getColor(R.color.colorAccent));
        this.mShowSwitch = obtainStyledAttributes.getBoolean(R.styleable.MyNameDetailView_showSwitch, false);
        boolean z = obtainStyledAttributes.getBoolean(R.styleable.MyNameDetailView_showImg, false);
        this.mShowEnter = obtainStyledAttributes.getBoolean(R.styleable.MyNameDetailView_showEnter, true);
        this.mContext = context;
        View inflate = LayoutInflater.from(context).inflate(R.layout.view_name_detail, (ViewGroup) this, true);
        this.mInflate = inflate;
        this.mImg = (ImageView) inflate.findViewById(R.id.id_img);
        this.mName = (TextView) this.mInflate.findViewById(R.id.id_name);
        this.mDetail = (TextView) this.mInflate.findViewById(R.id.id_detail);
        this.mSwitchCompat = (SwitchCompat) this.mInflate.findViewById(R.id.id_switch);
        this.mEnter = (ImageView) this.mInflate.findViewById(R.id.id_enter);
        if (!TextUtils.isEmpty(string)) {
            this.mName.setText(string);
        }
        if (!TextUtils.isEmpty(string2)) {
            this.mDetail.setVisibility(View.VISIBLE);
            this.mDetail.setText(string2);
        } else {
            this.mDetail.setVisibility(View.GONE);
        }
        if (z) {
            this.mImg.setVisibility(View.VISIBLE);
            Glide.with(context).load(Integer.valueOf(resourceId)).into(this.mImg);
            this.mImg.setColorFilter(color);
        } else {
            this.mImg.setVisibility(View.GONE);
        }
        if (this.mShowSwitch) {
            this.mSwitchCompat.setVisibility(View.VISIBLE);
            this.mEnter.setVisibility(View.GONE);
            this.mInflate.setOnClickListener(new OnClickListener() {
                /* class com.youyi.yyviewsdklibrary.View.MyNameDetailView.AnonymousClass1 */

                public void onClick(View view) {
                    if (MyNameDetailView.this.mSwitchCompat.isChecked()) {
                        MyNameDetailView.this.mSwitchCompat.setChecked(false);
                        if (MyNameDetailView.this.mOnItemClickListener != null) {
                            MyNameDetailView.this.mOnItemClickListener.onChecked(false);
                            return;
                        }
                        return;
                    }
                    MyNameDetailView.this.mSwitchCompat.setChecked(true);
                    if (MyNameDetailView.this.mOnItemClickListener != null) {
                        MyNameDetailView.this.mOnItemClickListener.onChecked(true);
                    }
                }
            });
            this.mSwitchCompat.setOnClickListener(new OnClickListener() {
                /* class com.youyi.yyviewsdklibrary.View.MyNameDetailView.AnonymousClass2 */

                public void onClick(View view) {
                    if (MyNameDetailView.this.mSwitchCompat.isChecked()) {
                        if (MyNameDetailView.this.mOnItemClickListener != null) {
                            MyNameDetailView.this.mOnItemClickListener.onChecked(true);
                        }
                    } else if (MyNameDetailView.this.mOnItemClickListener != null) {
                        MyNameDetailView.this.mOnItemClickListener.onChecked(false);
                    }
                }
            });
            return;
        }
        this.mSwitchCompat.setVisibility(View.GONE);
        if (this.mShowEnter) {
            this.mEnter.setVisibility(View.VISIBLE);
        } else {
            this.mEnter.setVisibility(View.GONE);
        }
        this.mInflate.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.MyNameDetailView.AnonymousClass3 */

            public void onClick(View view) {
                if (MyNameDetailView.this.mOnItemClickListener != null) {
                    MyNameDetailView.this.mOnItemClickListener.onItemClick(view);
                }
            }
        });
    }

    public void showSwitch(boolean z) {
        this.mShowSwitch = z;
        this.mShowEnter = !z;
        if (z) {
            this.mSwitchCompat.setVisibility(View.VISIBLE);
            this.mEnter.setVisibility(View.GONE);
            this.mInflate.setOnClickListener(new OnClickListener() {
                /* class com.youyi.yyviewsdklibrary.View.MyNameDetailView.AnonymousClass4 */

                public void onClick(View view) {
                    if (MyNameDetailView.this.mSwitchCompat.isChecked()) {
                        MyNameDetailView.this.mSwitchCompat.setChecked(false);
                        if (MyNameDetailView.this.mOnItemClickListener != null) {
                            MyNameDetailView.this.mOnItemClickListener.onChecked(false);
                            return;
                        }
                        return;
                    }
                    MyNameDetailView.this.mSwitchCompat.setChecked(true);
                    if (MyNameDetailView.this.mOnItemClickListener != null) {
                        MyNameDetailView.this.mOnItemClickListener.onChecked(true);
                    }
                }
            });
            this.mSwitchCompat.setOnClickListener(new OnClickListener() {
                /* class com.youyi.yyviewsdklibrary.View.MyNameDetailView.AnonymousClass5 */

                public void onClick(View view) {
                    if (MyNameDetailView.this.mSwitchCompat.isChecked()) {
                        if (MyNameDetailView.this.mOnItemClickListener != null) {
                            MyNameDetailView.this.mOnItemClickListener.onChecked(true);
                        }
                    } else if (MyNameDetailView.this.mOnItemClickListener != null) {
                        MyNameDetailView.this.mOnItemClickListener.onChecked(false);
                    }
                }
            });
            return;
        }
        this.mSwitchCompat.setVisibility(View.GONE);
        if (this.mShowEnter) {
            this.mEnter.setVisibility(View.VISIBLE);
        } else {
            this.mEnter.setVisibility(View.GONE);
        }
        this.mInflate.setOnClickListener(new OnClickListener() {
            /* class com.youyi.yyviewsdklibrary.View.MyNameDetailView.AnonymousClass6 */

            public void onClick(View view) {
                if (MyNameDetailView.this.mOnItemClickListener != null) {
                    MyNameDetailView.this.mOnItemClickListener.onItemClick(view);
                }
            }
        });
    }

    public void setTitle(String str) {
        TextView textView = this.mName;
        if (textView != null) {
            textView.setText(str);
        }
    }

    public void setDetail(String str) {
        TextView textView = this.mDetail;
        if (textView != null) {
            textView.setVisibility(View.VISIBLE);
            this.mDetail.setText(str);
        }
    }

    public void setSrcRes(int i) {
        if (this.mImg != null) {
            Glide.with(this.mContext).load(Integer.valueOf(i)).into(this.mImg);
        }
    }

    public void setSrcBitmap(Bitmap bitmap) {
        if (this.mImg != null) {
            Glide.with(this.mContext).load(bitmap).into(this.mImg);
        }
    }

    public void setChecked(boolean z) {
        SwitchCompat switchCompat = this.mSwitchCompat;
        if (switchCompat != null) {
            switchCompat.setChecked(z);
        }
    }
}
